package views
{
	import main.BattleMng;
	import main.ViewMng;
	
	import views.interfaces.IChat;
	import views.interfaces.IScreen;
	import views.interfaces.IUiBase;

	public class ScreenView implements IView
	{
		protected var _screen:IScreen;
		
		public function ScreenView()
		{
		}
		
		public function show():void
		{
			if( _screen == null )
			{
				var uiObj:IUiBase = ViewMng.instance().getUIByName( getUIName() );
				
				if( !uiObj ) return;
				
				_screen = IScreen( uiObj );
				
				_screen.onBattle = onBattle;
				
			}
			
			
			ViewMng.instance().addContent( _screen );
			
			_screen.show();
			
			
		}
		
		public function close():void
		{
			if( _screen )
				_screen.close();
		}
		
		
		private function chat():IChat
		{
			if( _screen )
			{
				return _screen.chat();
			}
			
			return null;	
		}
		
		
		public function getUIName():String
		{
			return UIAsset.UI_SCREEN;
		}
		
		public function isInited():Boolean
		{
			return _screen != null;
		}
		
		public function isShowed():Boolean
		{
			return _screen && _screen.isShowed();
		}
		
		protected function onBattle():void
		{
			ViewMng.instance().show( BattleView );
			BattleMng.instance().start( null );
			
		}
		
	}
}